<%--
  Created by IntelliJ IDEA.
  User: ddd
  Date: 2018/4/16
  Time: 17:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>新增题目</title>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" type="text/css" href="/static/css/admin.css">
</head>

<body>
<div style="padding: 15px;">
    <%--<form class="bs-example bs-example-form" role="form"  enctype="multipart/form-data" method="post" onsubmit="return SubForm(this)">--%>
    <form class="bs-example bs-example-form" role="form" action="/subject" enctype="multipart/form-data" method="post"
          onsubmit='return ValidForm()'>
        <table class="table">
            <tr>
                <td width="100" rowspan="2">题目：</td>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">汉：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="problem"
                                                      placeholder="请输入题目"></div>
                    </div>
                </td>
                <td rowspan="2">
                    <small>汉：</small>
                    <textarea rows="3" id="htmltitle" name="htmltitle" class="form-control"
                              style="height:60px;"></textarea></td>
                <td rowspan="2">
                    <small>藏：</small>
                    <textarea rows="3" id="zhtmltitle" name="zhtmltitle" class="form-control"
                              style="height:60px;"></textarea></td>
            </tr>
            <tr>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">藏：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="zproblem"
                                                      placeholder="ཁྱེད་ཀྱི་ཚད་ཁ་བྱང། "></div>
                    </div>
                </td>
            </tr>

            <tr>
                <td rowspan="2">选项A：</td>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">汉：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="optiona"
                                                      placeholder="请输入选项A"></div>
                    </div>
                </td>
                <td rowspan="2">
                    <small>汉：</small>
                    <textarea rows="3" id="htmla" name="htmla" class="form-control" style="height:60px;"></textarea>
                </td>
                <td rowspan="2">
                    <small>藏：</small>
                    <textarea rows="3" id="zhtmla" name="zhtmla" class="form-control" style="height:60px;"></textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">藏：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="zoptiona"
                                                      placeholder="ཁྱེད་ཀྱི་ཚད་བསལ་འདེམས།A"></div>
                    </div>
                </td>
            </tr>

            <tr>
                <td rowspan="2">选项B：</td>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">汉：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="optionb"
                                                      placeholder="请输入选项B"></div>
                    </div>
                </td>
                <td rowspan="2">
                    <small>汉：</small>
                    <textarea rows="3" id="htmlb" name="htmlb" class="form-control" style="height:60px;"></textarea>
                </td>
                <td rowspan="2">
                    <small>藏：</small>
                    <textarea rows="3" id="zhtmlb" name="zhtmlb" class="form-control" style="height:60px;"></textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">藏：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="zoptionb"
                                                      placeholder="ཁྱེད་ཀྱི་ཚད་བསལ་འདེམས།B"></div>
                    </div>
                </td>
            </tr>

            <tr>
                <td rowspan="2">选项C：</td>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">汉：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="optionc"
                                                      placeholder="请输入选项C"></div>
                    </div>
                </td>
                <td rowspan="2">
                    <small>汉：</small>
                    <textarea rows="3" id="htmlc" name="htmlc" class="form-control" style="height:60px;"></textarea>
                </td>
                <td rowspan="2">
                    <small>藏：</small>
                    <textarea rows="3" id="zhtmlc" name="zhtmlc" class="form-control" style="height:60px;"></textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">藏：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="zoptionc"
                                                      placeholder="ཁྱེད་ཀྱི་ཚད་བསལ་འདེམས།C"></div>
                    </div>
                </td>
            </tr>

            <tr>
                <td rowspan="2">选项D：</td>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">汉：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="optiond"
                                                      placeholder="请输入选项D"></div>
                    </div>
                </td>
                <td rowspan="2">
                    <small>汉：</small>
                    <textarea rows="3" id="htmld" name="htmld" class="form-control" style="height:60px;"></textarea>
                </td>
                <td rowspan="2">
                    <small>藏：</small>
                    <textarea rows="3" id="zhtmld" name="zhtmld" class="form-control" style="height:60px;"></textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="row">
                        <div class="col-lg-2" style="margin-top: 5px">
                            <small style="margin-left: 20px">藏：</small>
                        </div>
                        <div class="col-lg-10"><input type="text" class="form-control" name="zoptiond"
                                                      placeholder="ཁྱེད་ཀྱི་ཚད་བསལ་འདེམས།D"></div>
                    </div>
                </td>
            </tr>

            <tr>
                <td>类型：</td>
                <td>
                    <label><input type="radio" name="type" value="0">单选题</label>
                    <label><input type="radio" name="type" value="2">多选题</label>
                    <label><input type="radio" name="type" value="1">判断题</label>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>答案：</td>
                <td>
                    <input type="text" class="form-control" name="answer" placeholder="请输入答案，多选以'|'隔开，例如A|B"
                           onchange="ToUp(this)">
                </td>
                <td></td>
            </tr>
            <tr>
                <td>媒体类型：</td>
                <td><label><input type="radio" name="mtype" value="2">无</label> <label><input type="radio" name="mtype"
                                                                                              value="1">图片</label>
                    <label><input type="radio" name="mtype" value="2">视频</label></td>
                <td></td>
            </tr>
            <tr>
                <td>媒体上传：</td>
                <td><input type="file" name="mfile"></td>
                <td></td>
            </tr>
            <tr>
                <td>语音读题：</td>
                <td><input type="file" name="readfile"></td>
                <td>藏语语音读题：<input type="file" name="zreadfile" style="margin-top: -23px;margin-left: 180px"></td>
                <td></td>
            </tr>
            <tr>
                <td rowspan="2" style="border-top: 1px solid red">技巧描述：</td>
                <td style="border-top: 1px solid red"></td>
                <td rowspan="2" style="border-top: 1px solid red">
                    <small>汉：</small>
                    <textarea rows="3" id="explain" name="explain" class="form-control" style="height:60px;"></textarea>
                </td>
                <td rowspan="2" style="border-top: 1px solid red">
                    <small>藏：</small>
                    <textarea rows="3" id="zexplain" name="zexplain" class="form-control"
                              style="height:60px;"></textarea></td>
            </tr>
            <tr>
            </tr>
            <tr>
                <td>语音讲解：</td>
                <td><input type="file" name="examfile"></td>
                <td>藏语语音讲解：<input type="file" name="zexamfile" style="margin-top: -23px;margin-left: 180px"></td>
                <td></td>
            </tr>
            <tr>
                <td>技巧媒体类型：</td>
                <td><label><input type="radio" name="tmtype" value="2">无</label> <label><input type="radio"
                                                                                               name="tmtype" value="1">图片</label>
                    <label><input type="radio" name="tmtype" value="2">视频</label></td>
                <td></td>
            </tr>
            <tr>
                <td>技巧媒体上传：</td>
                <td><input type="file" name="emfile"></td>
                <td></td>
            </tr>
        </table>
        <button class="btn btn-primary btn-lg btn-block" type='submit'>提交保存</button>
    </form>
</div>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/jquery.form.min.js"></script>
<script src="/static/layer/layer.js"></script>
<!--副文本编辑器-->
<script charset="utf-8" src="/static/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh-CN.js"></script>
<script>
    $(function () {
        KindEditor.ready(function (K) {

            window.htmltitle = K.create('#htmltitle', {
//                width:"400px",
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });
            window.htmltitle = K.create('#zhtmltitle', {
//                width:"400px",
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });

            window.htmltitle = K.create('#htmla', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });
            window.htmltitle = K.create('#zhtmla', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });

            window.htmltitle = K.create('#htmlb', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });
            window.htmltitle = K.create('#zhtmlb', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });

            window.htmltitle = K.create('#htmlc', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });
            window.htmltitle = K.create('#zhtmlc', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });

            window.htmltitle = K.create('#htmld', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });
            window.htmltitle = K.create('#zhtmld', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });

            window.htmltitle = K.create('#explain', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });
            window.htmltitle = K.create('#zexplain', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat']
            });

        });
    });

    function closewin() {
        var ind = parent.layer.getFrameIndex(window.name);
        parent.layer.close(ind)
    }

    function ValidForm() {
        var problem = $('input[name=problem]').val() ,
            zproblem = $('input[name=zproblem]').val(),
            answer = $('input[name=answer]').val(),
            htmltitle = $('#htmltitle').val(),
            zhtmltitle = $('#zhtmltitle').val(),
            type = $("input[name='type']:checked").val(),
            mtype = $("input[name='mtype']:checked").val(),
            mfile = $('input[name=mfile]').val(),
            readfile = $('input[name=readfile]').val(),
            zreadfile = $('input[name=zreadfile]').val(),
            examfile = $('input[name=examfile]').val(),
            zexamfile = $('input[name=zexamfile]').val(),
            emfile = $('input[name=emfile]').val();
        if (!problem && !zproblem) {
            $('input[name=problem]').focus();
            layer.msg('请输入题目', {icon: 2, time: 1000});
            return false;
        }
        if (!answer) {
            $('input[name=answer]').focus();
            layer.msg('请输入答案', {icon: 2, time: 1000});
            return false;
        }
        if (typeof(type) == "undefined") {
            layer.msg('请选择题目类型', {icon: 2, time: 1000});
            return false;
        }
        if (typeof(mtype) == "undefined") {
            layer.msg('请选择媒体类型', {icon: 2, time: 1000});
            return false;
        }
        if (mtype != 2 && !mfile) {
            $('input[name=mfile]').focus();
            layer.msg('请上传媒体文件', {icon: 2, time: 1000});
            return false;
        }
      //  closewin()

    }


    function ToUp(obj) {
        var InputVal = $(obj).val();
        if (InputVal) {
            $(obj).val(InputVal.toUpperCase());
        }
    }
    
    $(".btn-block").click(function () {
        var key = $("input[name=answer]").val();
        if (key == "A") {
            $("input[name=answer]").val(1);
        }
        if (key == "B") {
            $("input[name=answer]").val(2);
        }
        if (key == "C") {
            $("input[name=answer]").val(4);
        }
        if (key == "D") {
            $("input[name=answer]").val(8);
        }
        if (key == "A|B"||key == "B|A") {
            $("input[name=answer]").val(3);
        }
        if (key == "A|C"||key == "C|A") {
            $("input[name=answer]").val(5);
        }
        if (key == "A|D"||key == "D|A") {
            $("input[name=answer]").val(9);
        }
        if (key == "B|C"||key == "C|B") {
            $("input[name=answer]").val(6);
        }
        if (key == "B|D"||key == "D|B") {
            $("input[name=answer]").val(10);
        }
        if (key == "C|D"||key == "D|C") {
            $("input[name=answer]").val(12);
        }
        if (key == "A|B|C"||key == "A|C|B"||key == "B|C|A"||key == "B|A|C"||key == "C|A|B"||key == "C|B|A") {
            $("input[name=answer]").val(7);
        }
        if (key == "A|B|D"||key == "A|D|B"||key == "B|A|D"||key == "B|D|A"||key == "D|A|B"||key == "D|B|A") {
            $("input[name=answer]").val(11);
        }
        if (key == "A|C|D"||key == "A|D|C"||key == "C|A|D"||key == "C|D|A"||key == "D|A|C"||key == "D|C|A") {
            $("input[name=answer]").val(13);
        }
        if (key == "B|C|D"||key == "B|D|C"||key == "C|B|D"||key == "C|D|B"||key == "D|B|C"||key == "D|C|B") {
            $("input[name=answer]").val(14);
        }
        if (key == "A|B|C|D"||key == "A|B|D|C"||key == "A|C|D|B"||key == "A|C|B|D"||key == "A|D|B|C"||key == "A|D|C|B"||key=="B|A|C|D"
            ||key=="B|A|D|C"||key=="B|C|A|D"||key=="B|C|D|A"||key=="B|D|A|C"||key=="B|D|C|A"||key=="C|A|B|D"||key=="C|A|D|B"
            ||key=="C|B|A|D"||key=="C|B|D|A"||key=="C|D|A|B"||key=="C|D|B|A"||key=="D|A|B|C"||key=="D|A|C|B"||key=="D|B|A|C"||key=="D|B|C|A"
            ||key=="D|C|B|A"||key=="D|C|A|B") {
            $("input[name=answer]").val(15);
        }
        if (key=="是"){
            $("input[name=answer]").val(1);
        }
        if (key=="否"){
            $("input[name=answer]").val(2);
        }
    })

</script>
</body>
</html>